package com.zqh.irmadscore.controller;


import com.zqh.irmadscore.model.dto.TractCombinationDTO;
import com.zqh.irmadscore.model.entity.MonitoringTracts;
import com.zqh.irmadscore.service.TractsService;
import com.zqh.irmadscore.utils.resultUtils.Result;
import com.zqh.irmadscore.utils.resultUtils.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/tracts")
@Tag(name = "监测道")
public class TractsController {

    private final TractsService tractsService;

    // 编写监测道的增删改查接口
    @Operation(summary = "获取全部监测道")
    @GetMapping("/getTracts")
    public Result<List<MonitoringTracts>> getNeeds() {

        List<MonitoringTracts> list = tractsService.list();

        return Result.ok(list);
    }

    @Operation(summary = "根据id获取监测道")
    @GetMapping("/getTractsById")
    public Result<MonitoringTracts> getNeedsById(Integer id) {

        MonitoringTracts monitoringTracts = tractsService.getById(id);

        return Result.ok(monitoringTracts);
    }

    //   删除监测道
    @Operation(summary = "根据id删除监测道")
    @GetMapping("/deleteTractsById")
    public Result<MonitoringTracts> deleteNeedsById(Integer id) {

        boolean b = tractsService.removeById(id);

        if(b)  return Result.ok();
        return Result.fail(null, ResultCodeEnum.FAIL.getMessage());
    }



    // 获取监测道组合
    @Operation(summary = "获取随机监测道组合事例")
    @GetMapping("/getTractsCombination")
    public Result<List<TractCombinationDTO>> getTractsCombination() {

        List<TractCombinationDTO> list = tractsService.getCombinationList();

        return Result.ok(list);
    }


}
